package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teaching.dao.TeachingBooktitleDao;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.TeachingBooktitle;
import com.ruoyi.teaching.service.ITeachingBooktitleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职称信息Controller
 * 
 * @author 孙嘉荣
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/teaching/booktitle")
public class TeachingBooktitleController extends BaseController
{
    @Autowired
    private ITeachingBooktitleService teachingBooktitleService;


    /**
     * 查询职称信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:booktitle:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingBooktitle teachingBooktitle)
    {
        startPage();
        List<TeachingBooktitle> list = teachingBooktitleService.selectTeachingBooktitleList(teachingBooktitle);
        return getDataTable(list);
    }

    /**
     * 导出职称信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:booktitle:export')")
    @Log(title = "职称信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingBooktitle teachingBooktitle)
    {
        List<TeachingBooktitle> list = teachingBooktitleService.selectTeachingBooktitleList(teachingBooktitle);
        ExcelUtil<TeachingBooktitle> util = new ExcelUtil<TeachingBooktitle>(TeachingBooktitle.class);
        util.exportExcel(response, list, "职称信息数据");
    }

    /**
     * 获取职称信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:booktitle:query')")
    @GetMapping(value = "/{booktitleId}")
    public AjaxResult getInfo(@PathVariable("booktitleId") Long booktitleId)
    {
        return AjaxResult.success(teachingBooktitleService.selectTeachingBooktitleByBooktitleId(booktitleId));
    }

    @GetMapping(value = "/listAll")
    public AjaxResult getAll()
    {
        TeachingBooktitle teachingBooktitle = new TeachingBooktitle();
        List<TeachingBooktitle> list = teachingBooktitleService.selectTeachingBooktitleList(teachingBooktitle);
        return AjaxResult.success(list);
    }

    /**
     * 新增职称信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:booktitle:add')")
    @Log(title = "职称信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingBooktitle teachingBooktitle)
    {
        return toAjax(teachingBooktitleService.insertTeachingBooktitle(teachingBooktitle));
    }

    /**
     * 修改职称信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:booktitle:edit')")
    @Log(title = "职称信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingBooktitle teachingBooktitle)
    {
        return toAjax(teachingBooktitleService.updateTeachingBooktitle(teachingBooktitle));
    }

    /**
     * 删除职称信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:booktitle:remove')")
    @Log(title = "职称信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{booktitleIds}")
    public AjaxResult remove(@PathVariable Long[] booktitleIds)
    {
        return toAjax(teachingBooktitleService.deleteTeachingBooktitleByBooktitleIds(booktitleIds));
    }
}
